package nl.grol.yakshop.web.util;

import javax.jdo.PersistenceManager;

public final class RequestContextHolder {
	private static final ThreadLocal<RequestContext> THREAD_LOCAL_CONTEXT = new ThreadLocal<RequestContext>();
	
	private RequestContextHolder() {
	}
	
	public static void removeContext() {
		THREAD_LOCAL_CONTEXT.remove();
	}
	
	public static void setContext(RequestContext context) {
		THREAD_LOCAL_CONTEXT.set(context);
	}

	public static PersistenceManager getPersistanceManager() {
        RequestContext requestContext = THREAD_LOCAL_CONTEXT.get();
		return requestContext.getPersistanceManager();
	}
	
	public static void incrementReadCount() {
	    RequestContext requestContext = THREAD_LOCAL_CONTEXT.get();
	    requestContext.incrementReadCounter();
	}
	
    public static void incrementWriteCount() {
        RequestContext requestContext = THREAD_LOCAL_CONTEXT.get();
        requestContext.incrementWriteCounter();
    }

}
